<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>prototype</title>
		<script>
			//给Date对象添加新方法
			Date.prototype.cnFormat=function(){
				return this.getFullYear()+"年"+(this.getMonth()+1)+"月"+this.getDate()+"年";
			}
			class Animal{
				//构造方法
				constructor(a,b){
					this.type=a;
					this.name=b;
				}
				say(){
					alert("我是一只"+this.type+"名字叫"+this.name+"的狗");
				}
			}
			
			var d=new Date();
			alert(d.cnFormat());
			Animal.prototype.sleep=function(){
				alert(this.name+"正在睡觉");
			}
			//trim
			var d2=new Animal("老鼠","米老鼠");
			d2.say();
			d2.sleep();
		</script>
	</head>
	<body>
	</body>
</html>
